﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Media;
using WPNextTools.NBase;
using WPNextTools.NConstant;


namespace WPNextTools.NControls
{
    public class PhotoListBoxItem : NContentControl
    {
        #region Fields
        internal IDataSourceItem associatedDataItem;
        private bool isBusy;//是不是在忙
        protected PhotoListBox owner;
        
        #endregion

        #region Properties
        internal PhotoListBox Owner
        {
            get
            {
                return this.owner;
            }
        }

       
        internal bool IsBusy
        {
            get
            {
                return this.isBusy;
            }
        }
        #endregion

        #region Constructor
        public PhotoListBoxItem()
        {
            base.DefaultStyleKey = typeof(PhotoListBoxItem);
        }
        #endregion

        #region ContainerWidthItem
        /// <summary>
        /// 设置数据源
        /// </summary>
        /// <param name="item"></param>
        internal virtual void BindToDataItem(IDataSourceItem item)
        {
            this.associatedDataItem = item;
            this.isBusy = true;
            base.SetValue(FrameworkElement.DataContextProperty, item.Value);
        }

        internal virtual void RealeaseFromDataItem()
        {
            this.associatedDataItem = null;
            this.isBusy = false;
            this.ClearValue(ContentControl.ContentProperty);
            this.ClearValue(ContentControl.ContentTemplateProperty);
            this.ClearValue(FrameworkElement.DataContextProperty);
            //this.SetValue(FrameworkElement.DataContextProperty, null);
        }
        #endregion
        
        #region Detach
        internal virtual void Detach()
        {
            this.OnDetaching();
            this.owner = null;
            this.OnDetached();
        }

        protected virtual void OnDetached()
        {
            
        }

        protected virtual void OnDetaching()
        {

        }
        #endregion

        #region Attach
        internal virtual void Attach(PhotoListBox owner)
        {
            this.owner = owner;
            this.OnAttached();
        }

        protected virtual void OnAttached()
        {
           
        }
      
        protected override void OnTap(GestureEventArgs e)
        {
            this.owner.OnItemTap(this);
        }
     
        #endregion

        #region SetOffset

        internal void SetHorizontalOffset(double offset)
        {
            Canvas.SetLeft(this, offset);
        }

        internal void SetVerticalOffset(double offset)
        {
            Canvas.SetTop(this, offset);
        }

        internal void SetZIndex(int value)
        {
            Canvas.SetZIndex(this, value);
        }
        #endregion

      
    }
}
